import React from "react"
import { Redirect, Route, Switch } from "react-router-dom"
import Login from "../views/login/Login"
import Home from "../views/home/Home"
import AuthRoute from "@/components/AuthRoute"

const IndexRouter: React.FC = () => {
  return (
    <Switch>
      <Route
        path={"/login"}
        render={(props) => (
          <AuthRoute {...props}>
            <Login />
          </AuthRoute>
        )}
      />
      <Route
        path={"/home"}
        render={(props) => (
          <AuthRoute {...props}>
            <Home />
          </AuthRoute>
        )}
      />

      <Redirect from="/" to={sessionStorage.getItem("token") !== null ? "/home" : "/login"} />
    </Switch>
  )
}

export default IndexRouter
